package com.zero.controller;

import com.zero.entity.Condition;
import com.zero.entity.Pay;
import com.zero.entity.PayType;
import com.zero.service.PayService;
import com.zero.service.PayTypeService;
import com.zero.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayTypeService payTypeService;

    @Autowired
    private PayService payService;

    @PostMapping("/type")
    public Result typeList(@RequestBody PayType payType, HttpServletRequest request){
        return payTypeService.select(payType, request);
    }

    @GetMapping("/type")
    public Result typeList(HttpServletRequest request){
        return payTypeService.select(request);
    }

    @PostMapping("/addType")
    public Result addType(@RequestBody PayType payType, HttpServletRequest request){
        return payTypeService.add(payType, request);
    }

    @GetMapping("/deleteType")
    public Result deleteType(@RequestParam("ids") String ids){
        return payTypeService.delete(ids);
    }

    @PostMapping("/updateType")
    public Result updateType(@RequestBody PayType payType){
        return payTypeService.update(payType);
    }


    @PostMapping("/list")
    public Result payList(@RequestBody Condition condition, HttpServletRequest request){
        return payService.select(condition, request);
    }

    @PostMapping("addPay")
    public Result addPay(@RequestBody Pay pay, HttpServletRequest request){
        return payService.add(pay, request);
    }

    @GetMapping("/deletePay")
    public Result deletePay(@RequestParam("ids") String ids, HttpServletRequest request){
        return payService.delete(ids, request);
    }

    @PostMapping("/updatePay")
    public Result updatePay(@RequestBody Pay pay, HttpServletRequest request){
        return payService.update(pay, request);
    }
}
